﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Net.IRepository;
using Net.Model.Entities.User;
using Net.Model.ViewModels.Basic;
using SqlSugar;

namespace Net.Repository
{
    public class UserRepository : BaseRepository<CoreCmsUser>, IUserRepository
    {
        public UserRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
        {

        }

        public async Task<IPageList<CoreCmsUser>> QueryPageAsync(Expression<Func<CoreCmsUser, bool>> predicate, Expression<Func<CoreCmsUser, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1, int pageSize = 20)
        {
            RefAsync<int> totalCount = 0;
            var page = await DbClient.Queryable<CoreCmsUser>()
                .Select(p=> new CoreCmsUser()
                {
                    id = p.id,
                    userName = p.userName,
                    passWord = p.passWord,                  
                })
                .MergeTable().With(SqlWith.Null)
                .OrderBy(orderByExpression, orderByType)
                .Where(predicate)
                .ToPageListAsync(pageIndex, pageSize, totalCount);
            var list = new PageList<CoreCmsUser>(page, pageIndex, pageSize, totalCount);
            return list;
        }
    }
}
